//
//  BySuperLottoListBottomView.m
//  caipiao_ios
//
//  Created by mc on 2018/7/16.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "BySuperLottoListBottomView.h"



@implementation BySuperLottoListBottomView

- (id)init{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        UIView *backgroundView = [[UIView alloc] init];
        [self addSubview:backgroundView];
        [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.top.equalTo(self).offset(0);
            make.right.equalTo(self).offset(0);
            make.height.mas_equalTo(@50);
        }];
        
        
        
        UIView *playView = [[UIView alloc] init];
        [backgroundView addSubview:playView];
        [playView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(backgroundView).offset(0);
            make.centerY.equalTo(backgroundView).offset(0);
            make.size.mas_equalTo(CGSizeMake(75, 20));
        }];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [playView addGestureRecognizer:tap];
        
        UILabel *playLabel = [[UILabel alloc] init];
        [playView addSubview:playLabel];
        [playLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(playView).offset(0);
            make.top.equalTo(playView).offset(0);
            make.bottom.equalTo(playView).offset(0);
            make.left.equalTo(playView).offset(18);
        }];
        playLabel.font = FONT(12);
        playLabel.text = @"规则说明";
        playLabel.textColor = BY_Blue_COLOR;
        
        UIImageView *imageView = [[UIImageView alloc] init];
        [playView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(playView).offset(0);
            make.centerY.equalTo(playView).offset(0);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        imageView.image = [UIImage imageNamed:@"wanfashuoming"];
        imageView.userInteractionEnabled = YES;
        
        
        UILabel *line1 = [[UILabel alloc] init];
        [backgroundView addSubview:line1];
        [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset(0);
            make.right.equalTo(backgroundView).offset(0);
            make.bottom.equalTo(backgroundView).offset(0);
            make.height.mas_equalTo(@1);
        }];
        line1.backgroundColor  = BY_LINE_COLOR;
        
        
        UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:sureBtn];
        [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(0);
            make.height.mas_equalTo(@50);
            make.width.mas_equalTo(@100);
        }];
        sureBtn.backgroundColor = BY_THEME_COLOR;
        [sureBtn setTitle:@"投注" forState:UIControlStateNormal];
        [sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        sureBtn.titleLabel.font = FONT(14);
        sureBtn.tag = 100;
        
        
       
        
        UIButton *selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [backgroundView addSubview:selectBtn];
        [selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10);
            make.centerY.equalTo(backgroundView).offset(0);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        [selectBtn setImage:[UIImage imageNamed:@"gendan-shuliangquan"] forState:UIControlStateNormal];
        [selectBtn setImage:[UIImage imageNamed:@"zhongjiang1111111"] forState:UIControlStateSelected];
        selectBtn.selected = NO;
        selectBtn.tag = 200;
        [selectBtn addTarget:self action:@selector(selectAction:) forControlEvents:UIControlEventTouchUpInside];
        [sureBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
      
        UILabel *randomLabel = [[UILabel alloc] init];
        [backgroundView addSubview:randomLabel];
        [randomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(selectBtn.mas_right).offset(5);
            make.centerY.equalTo(backgroundView).offset(0);
            make.size.mas_equalTo(CGSizeMake(75, 20));
        }];
        
        randomLabel.font = FONT(12);
        randomLabel.textColor = [UIColor lightGrayColor];
        randomLabel.text = @"随机追号";
        
   
        
        
        UIButton *selectBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:selectBtn2];
        [selectBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(sureBtn.mas_centerY).offset(0);
            make.left.equalTo(self).offset(10);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        [selectBtn2 setImage:[UIImage imageNamed:@"hongqiuweixuanzhong"] forState:UIControlStateNormal];
        [selectBtn2 setImage:[UIImage imageNamed:@"tongyi"] forState:UIControlStateSelected];
        selectBtn2.selected = YES;
        selectBtn2.tag = 201;
        [selectBtn2 addTarget:self action:@selector(selectAction:) forControlEvents:UIControlEventTouchUpInside];
        
       
        
        
        UILabel *moneyLabel = [[UILabel alloc] init];
        [self addSubview:moneyLabel];
        [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(sureBtn.mas_left).offset(-10);
            make.top.equalTo(sureBtn.mas_top).offset(5);
            make.size.mas_equalTo(CGSizeMake(100, 15));
        }];
        moneyLabel.text = @"0元";
        moneyLabel.font = FONT(12);
        moneyLabel.textColor = BY_THEME_COLOR;
        moneyLabel.textAlignment = NSTextAlignmentRight;
        
        UILabel *otherLabel = [[UILabel alloc] init];
        [self addSubview:otherLabel];
        [otherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(moneyLabel.mas_left).offset(0);
            make.right.equalTo(moneyLabel.mas_right).offset(0);
            make.top.equalTo(moneyLabel.mas_bottom).offset(5);
            make.height.mas_equalTo(@15);
        }];
        otherLabel.font = FONT(12);
        otherLabel.textColor = BY_TEXT_COLOR;
        otherLabel.text = @"0注1倍1期";
        otherLabel.textAlignment = NSTextAlignmentRight;
        
        
        UITextView *noteLabel = [[UITextView alloc] init];
        [self addSubview:noteLabel];
        [noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(selectBtn2.mas_right).offset(5);
            make.centerY.equalTo(selectBtn2.mas_centerY).offset(0);
            make.right.equalTo(moneyLabel.mas_left).offset(-10);
            make.height.mas_equalTo(@50);
        }];
        noteLabel.font = FONT(12);
        noteLabel.textColor = BY_TEXT_COLOR;
        noteLabel.text = @"我已阅读并同意《服务协议》";
        noteLabel.delegate = self;
        noteLabel.editable = NO;
        noteLabel.scrollEnabled = NO;
        
        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:noteLabel.text];
        [attributeString addAttribute:NSLinkAttributeName value:@"xieyi://" range:[noteLabel.text rangeOfString:@"《服务协议》"]];
        [attributeString addAttribute:NSForegroundColorAttributeName value:BY_Blue_COLOR range:[noteLabel.text rangeOfString:@"《服务协议》"]];
        noteLabel.attributedText = attributeString;
        
        
        
        self.otherLabel = otherLabel;
        self.moneyLabel = moneyLabel;
        self.selectBtn = selectBtn;
        self.selectBtn2 = selectBtn2;
        
        
        
        BySuperLottoAddMinusView *addMinusView1 = [[BySuperLottoAddMinusView alloc] init];
        [self addSubview:addMinusView1];
        [addMinusView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.top.equalTo(backgroundView.mas_bottom).offset(0);
            make.size.mas_equalTo(CGSizeMake(150, 50));
        }];
        addMinusView1.buyLabel.text = @"追";
        addMinusView1.timesLabel.text = @"期";
        
        BySuperLottoAddMinusView *addMinusView2 = [[BySuperLottoAddMinusView alloc] init];
        [self addSubview:addMinusView2];
        [addMinusView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-10);
            make.centerY.equalTo(addMinusView1.mas_centerY).offset(0);
            make.size.mas_equalTo(CGSizeMake(150, 50));
        }];
        addMinusView2.buyLabel.text = @"买";
        addMinusView2.timesLabel.text = @"倍";
        self.addMinusView1 = addMinusView1;
        self.addMinusView2 = addMinusView2;
        
        
        
        UILabel *line2 = [[UILabel alloc] init];
        [self addSubview:line2];
        [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.right.equalTo(self).offset(0);
            make.bottom.equalTo(sureBtn.mas_top).offset(0);
            make.height.mas_equalTo(@1);
        }];
        line2.backgroundColor  = BY_LINE_COLOR;
        
    }
    return self;
}


- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
    
    if ([[URL scheme] isEqualToString:@"xieyi"]) {
        
        ByWebViewController *vc = [[ByWebViewController alloc] initWithTotalUrlString:[NSString stringWithFormat:@"%@/Wanfajiesao/service?type=0",BOYE_WEB_BASE_URL]];
        vc.titleString = @"服务协议";
        [(ByBaseVC *)self.viewController by_normalPush:vc hasNavi:YES];
        return NO;
    }
    return YES;
}


- (void)selectAction:(UIButton *)btn{
    btn.selected = !btn.selected;
}


- (void)btnAction:(UIButton *)btn{
    
    if (btn.tag == 100) {
        if (!self.selectBtn2.selected) {
            [ByCoreToolAlert showOnlyText:@"必须阅读并同意《服务协议》"];
            return;
        }
        
        if (self.sureBlock) {
            self.sureBlock();
        }
    }
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    
    if (self.ruleBlock) {
        self.ruleBlock();
    }
}



@end
